package com.fulihui.wgj.consumer.common.var;

import com.alibaba.dubbo.config.annotation.Reference;
import com.fulihui.cloud.gameplatform.api.GameClassifyService;
import com.fulihui.cloud.gameplatform.dto.GameTagClassifyInfoDTO;
import com.fulihui.cloud.gameplatform.dto.GameTagWarehouseInfoDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.Map;

/**
 * @author: LiuJie
 * @version: 2018/5/18 13:22
 * @description:
 */
@Component
@Slf4j
public class GameLabelVar {
    /**
     * 游戏类型缓存
     * key -> GameNumber
     * value -> ClassifyId
     */
    public static Map<String,Long> gameDic ;

    @Reference(version = "1.0.0")
    private GameClassifyService gameClassifyService;

    @PostConstruct
    public void init(){
        refreshGameType();
    }

    public void refreshGameType(){
        Map<String,Long> tmp = new HashMap<>();
        //找出所有类别
        for (GameTagClassifyInfoDTO gameTagClassifyInfoDTO : gameClassifyService.queryAllGameClassify().getValues()) {
            //循环类别找出 每个类别的游戏
            for (GameTagWarehouseInfoDTO gameTagWarehouseInfoDTO : gameClassifyService.queryGamesByClassifyId(gameTagClassifyInfoDTO.getId()).getValues()) {
                tmp.put(gameTagWarehouseInfoDTO.getGameNumber(),gameTagClassifyInfoDTO.getId());
            }
        }
        //刷新缓存
        gameDic = tmp;
        log.info("游戏类别缓存已刷新！！{}",tmp);
    }
}
